#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

class prefixComp
{
public:
	const string& t;

	prefixComp(const string& src) : t(src) {}

	bool operator()(int a,int b) {
		if (a == b)
			return false;
		int i = 0;
		for(; i < t.length(); ++i)
			if (t[(i + a)%t.length()] != t[(i + b)%t.length()])
				return t[(i + a)%t.length()] < t[(i + b)%t.length()];
		if (i == t.length())
			return true;
		else return false;
	}
};

int main() {
	string t;

	cin>>t;

	vector<int> prefs;
	prefs.resize(t.length());
	for(int i = 0; i < t.length(); ++i)
		prefs[i] = i;

	prefixComp comp(t); 
	sort(prefs.begin(),prefs.end(),comp);



	int k = 0;
	while(k != -1 ) {
		cin>>k;
		if (k >= 0 && k < t.length()) {
			int beg = prefs[k];
			for(int i = 0; i < t.length(); ++i)
				cout<<t[(beg + i)%t.length()];
			cout<<endl;
		}
	}

	system("pause");

	return 0;
}